

## Attention This library should be completely independent of the Simulation
## 			 project so that it can be included in different programs.

CC      = @CGCC@
CFLAGS  = `@prefix@/bin/mylibs-config --cflags`
LNK     = `@prefix@/bin/mylibs-config --ldflags`

SDL_CONFIG= $(shell sdl-config --cflags --libs)

CPPFILES = $(shell ls *.cpp)
HPPFILES = $(shell ls *.hpp)
OFILES   = $(CPPFILES:%.cpp=%.o)


libMCubes.a: $(OFILES)
	rm -f libMCubes.a
	ar -r libMCubes.a $(OFILES)
	ar -t libMCubes.a

%.o: %.cpp $(HPPFILES)
	$(CC) $(CFLAGS) $(OPT) -c $<

# build documentation - not automatically
doc:
	@echo "================= Building Documentation ===================="
	doxygen Doxyfile > doxygen.log
	@echo "See doxygen.log for further information"

install:libMCubes.a
	@echo "================= Installing MCubes =========================="
	@echo "Installing into  @prefix@/stow/mylibs/"
	@echo  @prefix@/stow/mylibs/ > prefix.log

	mkdir -p @prefix@/stow/mylibs/bin
	mkdir -p @prefix@/stow/mylibs/lib
	mkdir -p @prefix@/stow/mylibs/include/MCubes;

	install --mode=755 MCubes-config @prefix@/stow/mylibs/bin/MCubes-config

	install --mode=744 *.a @prefix@/stow/mylibs/lib/;
	sed 's/#include[ \t]*"\([^"]*\)"/#include "MCubes\/\1"/g' MCubes.hpp > @prefix@/stow/mylibs/include/MCubes.hpp
	install --mode=744 Cube.hpp Grid.hpp Mesh.hpp Tables.hpp Triangle.hpp @prefix@/stow/mylibs/include/MCubes;
	@echo "=============================================================="


uninstall:
	cd @prefix@/stow/mylibs/include/ && rm -rvf MCubes MCubes.hpp && cd -;
	cd @prefix@/stow/mylibs/lib/ && rm -vf libMCubes.a && cd -;
	cd @prefix@/stow/mylibs/bin/ && rm -vf MCubes-config && cd -;

clean:
	@echo "======================== Clean Up ==========================="
	rm -rif *.o doxygen.log libMCubes.a
	make -C Testing clean
	rm -rif doc latex
